package com;

import com.fz.entity.Stu;
import com.fz.entity.Student;
import com.fz.mapper.StudentMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by ZCY on 2018-01-19.
 */
@Slf4j
public class Demo {
    protected SqlSession session = null;
    @Before
    public void init() {
        InputStream is = null;
        try {
            is = Resources.getResourceAsStream("conf.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(is);
        this.session = sf.openSession();
    }

    @After
    public void close() {
        session.commit();
        session.close();
    }

    @Test
    public  void add(){
          StudentMapper sm = this.session.getMapper(StudentMapper.class);
        //  sm.show();
        List<Student>  list = sm.show();
        for (Student s:list){
            //log.error(s.toString());
        }

        List<Student>  list2 = sm.myshow();
        for (Student s:list2){
          //  log.error(s.toString());
        }
        List<Stu> list3 = sm.ssshow();
        for(Stu ss:list3){
           // log.error(ss.toString());
        }

        /*根据id进行删除*/
        sm.delByid(16);



    }

}
